package com.qiang.manager.service;

import com.qiang.manager.dao.IstudentDao;
import com.qiang.manager.domain.Student;
import com.qiang.manager.factory.Factory;

import java.util.ArrayList;

public class StudentServiceImp implements IstudentSerice {

    //创建对象
    IstudentDao dao = Factory.getStudentDao();

    @Override
    public void addStudent(Student student) {
        dao.addStudent(student);
    }

    @Override
    public void deleteStudent(String id) {
        dao.deleteStudent(id);
    }

    @Override
    public void updateStudent(String id, Student newstudent) {
        dao.updateStudent(id, newstudent);
    }

    @Override
    public ArrayList<Student> findStudent() {
        ArrayList<Student> student = dao.findStudent();
        return student;
    }

    @Override
    //判断id是否存在的方法
    public boolean Exit(String id) {
        ArrayList<Student> student = dao.findStudent();
        //遍历集合
        for (int i = 0; i < student.size(); i++) {
            if (student.get(i) != null && student.get(i).getId().equals(id)) {
                return true;
            }
        }
        return false;
    }
}
